<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Realtest extends CI_Controller {
	var $userInfo;
	function __construct() {
		parent::__construct();
		$this->load->model('common/usersession_model');
		$this->userInfo = $this->usersession_model->getUser();
		if(empty($this->userInfo)){
			redirect('/user/login');
			return;
		}
	}
	
	public function testList(){
		$this->load->model('test/device_model');
		$devices = $this->device_model->findAllDevices('devices.id, devices.name, devices.image, devices.address, devices.ctime, brands.name as brand_name, operation_systems.name as os_name, resolutions.name as resolution_name');

		if(!empty($devices)){
			foreach ($devices as &$device) {
				$ctime = strtotime($device['ctime']);
				$dValue = $ctime - time(); 
				if($dValue <= (10 * 24 * 60 * 60)){
					$device['isNew'] = true;
				}else{
					$device['isNew'] = false;
				}
			}
		}
		
		$data = array('devices' => $devices);
		$this->load->view('realtest/list.php',$data);
	}
	
	public function bookDevice(){
		$deviceId = $this->input->get_post('deviceId');
		$imei = $this->input->get_post('imei');
		$serverId = $this->input->get_post('pcId');
		$userId = $this->userInfo['id'];
		
		$serverId = 1;
		
		// TODO 检查是否已被占用
		$this->load->model('test/device_model');
		$this->device_model->book($userId, $deviceId, $imei, $serverId);
		
		$this->load->view('realtest/device_detail_info.php');
	}
	
	public function emulator(){
		//data : "pcId="+pcId+"&imei="+imei+"&modelId="+modelId+"&picUrlB="+picUrlB,
		$this->load->view('realtest/emulator.php');
	}
	
}